package com.future.mayi.activity;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.future.baselib.utils.statusbarlibrary.StatusBarUtils;
import com.future.mayi.R;
import com.future.mayi.dialog.CommonDialog;
import com.future.mayi.fragment.RozenLogFragment;
import com.future.mayi.fragment.WalletInFragment;
import com.future.mayi.utils.PriceUtils;
import com.future.mayi.utils.SharedPreferencesUtils;
import com.future.mayi.widget.WalletTabLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class WalletActivity extends BaseActivity {

    @BindView(R.id.tv_money)
    TextView tvMoney;
    @BindView(R.id.tv_withdraw)
    TextView tvWithdraw;

    @BindView(R.id.tab_layout)
    WalletTabLayout tabLayout;
    @BindView(R.id.view_pager)
    ViewPager viewPager;
    @BindView(R.id.tv_lock_price)
    TextView tvLockPrice;

    private WalletInFragment inFragment;
    private WalletInFragment payFragment;
    private RozenLogFragment rozenLogFragment;

    private List<Fragment> fragmentList;
    private List<String> listTitle;

    protected void initTopBar() {

    }

    @Override
    protected void initLayout() {
        StatusBarUtils.setStatusBarColor(getWindow(), getResources().getColor(R.color.main_color), false);
        setContentView(R.layout.activity_wallet);
    }

    @Override
    protected void initView() {


        listTitle = new ArrayList<>(2);
        fragmentList = new ArrayList<>(2);

        listTitle.add("收入");
        listTitle.add("支出");
        listTitle.add("即将到账");

        inFragment = new WalletInFragment();
        inFragment.setType(0);
        fragmentList.add(inFragment);

        payFragment = new WalletInFragment();
        payFragment.setType(1);
        fragmentList.add(payFragment);

        rozenLogFragment = new RozenLogFragment();
        fragmentList.add(rozenLogFragment);
        viewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return fragmentList.get(position);
            }

            @Override
            public int getCount() {
                return fragmentList.size();
            }

            @Override
            public CharSequence getPageTitle(int position) {
                if (listTitle != null && listTitle.size() > 0) {
                    return listTitle.get(position);
                }
                return super.getPageTitle(position);
            }
        });
        tabLayout.setupWithViewPager(viewPager);


    }

    @Override
    protected void initDates() {
    }

    @Override
    protected void initListener() {

    }


    public void setPrice(double money, double frozen) {
        tvMoney.setText(PriceUtils.getPriceText2(money));
        tvLockPrice.setText(PriceUtils.getPriceText2(frozen));
    }


    @OnClick({R.id.iv_title_left, R.id.tv_right, R.id.tv_withdraw, R.id.tv_lock_price_hint})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_title_left:
                onBackPressed();
                break;
            case R.id.tv_right:
                startActivity(PerformanceActivity.class);
                break;
            case R.id.tv_withdraw:
                startActivity(new Intent(this, WithdrawActivity.class));
                break;
            case R.id.tv_lock_price_hint:
                new CommonDialog.Builder(mContext)
                        .setCancelable(false)
                        .setMessage("付款成功的订单，订单佣金将冻结在您的账号，待订单确认收货后，冻结金额将自动释放到您的余额")
                        .setPositiveButton("我知道了", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                            }
                        })
                        .setPositiveButtonColor(R.color.text_colorfe7712)
                        .show();
                break;
        }
    }


    public void setShowWithdraw(boolean show) {
        if (tvWithdraw == null) return;
        tvWithdraw.setVisibility(show ? View.VISIBLE : View.GONE);
    }

}
